package nowcoder;

import java.util.Scanner;

/**
 * 例如：cdabbacc，返回4
 *
 * 思路：遍历每一个位置，从当前位置为中心求回文串长度，最后得到最大长度
 */
public class 最长回文串 {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);
        while(s.hasNext()) {
            System.out.println(maxRecycleLength(s.next()));
        }
    }

    public static int maxRecycleLength(String str) {
        int maxLength = 1;
        for (int i = 0; i < str.length(); i++) {
            int length = recycleLength(str, i);
            if (length > maxLength) {
                maxLength = length;
            }
        }
        return maxLength;
    }

    public static int recycleLength(String str, int index) {

        int max = 1;
        if (index - 1 >= 0 && index + 1 < str.length() && str.charAt(index - 1) == str.charAt(index + 1)) {
            int count = 2;
            while (index - count >= 0 && index + count < str.length()
                    && str.charAt(index - count) == str.charAt(index + count)) {
                count++;
            }
            max = 2 * (count - 1) + 1;
        }

        if (index + 1 < str.length() && str.charAt(index) == str.charAt(index + 1)) {
            int count = 2;
            while (index - count + 1 >= 0 && index + count < str.length()
                    && str.charAt(index - count + 1) == str.charAt(index + count)) {
                count++;
            }

            if (2 * (count - 1) > max) {
                max = 2 * (count - 1);
            }
        }

        return max;
    }
}
